function ev = cvc_eventhash(EEG,str)
% CVC_EVENTHASH
%
%  Synopsis
%  ========
%
%  ev  = cvc_eventhash(EEG,str)
%  str = cvc_eventhash(EEG,ev)
%
%  -- Author: Mads Dyrholm --
%     Center for Visual Cognition, University of Copenhagen.
%     June 2011
%
%  Purpose
%  =======
%
%  To get the event type given an event type string as
%  returned by cvc_eventlist.
%
%  Inputs/Outputs
%  ==============
%
%  EEG - EEGLAB dataset.
%
%  str - Event type string.
%
%  ev - The corresponding event type number.

if isstr(str)
  ev = [];
  for no=1:length(EEG.cvc.edatevents.evtype)
    if strcmp( EEG.cvc.edatevents.description{no} , str )
      ev = EEG.cvc.edatevents.evtype(no);
      break;
    end
  end
else  
  ev = [];
  for no=1:length(EEG.cvc.edatevents.evtype)
    if EEG.cvc.edatevents.evtype(no)==str
      ev = EEG.cvc.edatevents.description(no);
      break;
    end
  end
end
